# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=leptonica

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.70
pkgrel=2
pkgdesc="Leptonica library (mingw-w64)"
arch=('any')
url="http://www.leptonica.org"
license=("Leptonica")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=(${MINGW_PACKAGE_PREFIX}-gcc-libs
        ${MINGW_PACKAGE_PREFIX}-libjpeg-turbo
        ${MINGW_PACKAGE_PREFIX}-libtiff
        ${MINGW_PACKAGE_PREFIX}-libpng
        ${MINGW_PACKAGE_PREFIX}-giflib
        ${MINGW_PACKAGE_PREFIX}-libwebp
        ${MINGW_PACKAGE_PREFIX}-zlib)
options=('!libtool' 'strip')
source=("http://www.leptonica.org/source/${_realname}-${pkgver}.tar.gz"
        giflib.patch)
md5sums=('5ac2a31cf5b4f0e8f5a853a5266c42ef'
         'b1c61c331f58ac5dc3dce595cfe9246a')

prepare() {
  cd "$srcdir/${_realname}-$pkgver"
  patch -p1 -i ${srcdir}/giflib.patch
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ${srcdir}/${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX}
  
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="$pkgdir" install
}
